import { deleteByPrimaryKeyForArea, selectByPrimaryKeyForArea, insertForArea, updateForArea, deleteByMapForArea,updateByMapForArea, getOneForArea,getAllForArea,queryPageForArea, countForArea, insertBatchForArea, deleteBatchForArea,updateBatchForArea,getAreaTreeByParentid,updateChangeTargetNodeWithSourceNode } from '@/services/system/api_area';

export default {
    namespace: 'area',

    state: {
        data: {
            list: [],
        },
        areaTree: {
        	list: [],
        },
        recorddata: {
            datarecord:{},
            message:null,
            success: false,
        },
    },

    effects: {
            *delete_by_primarykey_for_area({ payload,callback }, { call, put }) {
                const response = yield call(deleteByPrimaryKeyForArea, payload);
                yield put({
                    type: 'deleteByPrimaryKeyForArea',
                    payload: response,
                });

				if (callback) callback();
            },
            *select_by_primarykey_for_area({ payload, callback }, { call, put }) {
                const response = yield call(selectByPrimaryKeyForArea, payload);
                yield put({
                    type: 'selectByPrimaryKeyForArea',
                    payload: response,
                });

                const responsedata = yield call(queryPageForArea, {});
                yield put({
                type: 'queryPageForArea',
                payload: responsedata,
                });

                if (callback) callback();
            },
            *insert_for_area({ payload, callback }, { call, put }) {
                const response = yield call(insertForArea, payload);
                yield put({
                    type: 'insertForArea',
                    payload: response,
                });

                if (callback) callback();
            },
            *update_for_area({ payload, callback }, { call, put }) {
                const response = yield call(updateForArea, payload);
                yield put({
                    type: 'updateForArea',
                    payload: response,
                });

                if (callback) callback();
            },
            *delete_by_map_for_area({ payload, callback }, { call, put }) {
                const response = yield call(deleteByMapForArea, payload);
                yield put({
                    type: 'deleteByMapForArea',
                    payload: response,
                });


                const responsedata = yield call(queryPageForArea, {});
                yield put({
                type: 'queryPageForArea',
                payload: responsedata,
                });

                if (callback) callback();
            },
            *update_by_map_for_area({ payload, callback }, { call, put }) {
                const response = yield call(updateByMapForArea, payload);
                yield put({
                    type: 'updateByMapForArea',
                    payload: response,
                });


                const responsedata = yield call(queryPageForArea, {});
                yield put({
                type: 'queryPageForArea',
                payload: responsedata,
                });

                if (callback) callback();
            },
            *get_one_for_area({ payload, callback }, { call, put }) {
                const response = yield call(getOneForArea, payload);
                yield put({
                    type: 'getOneForArea',
                    payload: response,
                });


                const responsedata = yield call(queryPageForArea, {});
                yield put({
                type: 'queryPageForArea',
                payload: responsedata,
                });

                if (callback) callback();
            },
            *get_all_for_area({ payload, callback }, { call, put }) {
                const response = yield call(getAllForArea, payload);
                yield put({
                    type: 'getAllForArea',
                    payload: response,
                });

                const responsedata = yield call(queryPageForArea, {});
                yield put({
                type: 'queryPageForArea',
                payload: responsedata,
                });

                if (callback) callback();
            },
            *query_page_for_area({ payload, callback }, { call, put }) {
                const response = yield call(queryPageForArea, payload);
                yield put({
                    type: 'queryPageForArea',
                    payload: response,
                });


                const responsedata = yield call(queryPageForArea, {});
                yield put({
                type: 'queryPageForArea',
                payload: responsedata,
                });

                if (callback) callback();
            },
            *count_for_area({ payload, callback }, { call, put }) {
                const response = yield call(countForArea, payload);
                yield put({
                    type: 'countForArea',
                    payload: response,
                });


                const responsedata = yield call(queryPageForArea, {});
                yield put({
                type: 'queryPageForArea',
                payload: responsedata,
                });

                if (callback) callback();
            },
            *insert_batch_for_area({ payload, callback }, { call, put }) {
                const response = yield call(insertBatchForArea, payload);
                yield put({
                    type: 'insertBatchForArea',
                    payload: response,
                });


                const responsedata = yield call(queryPageForArea, {});
                yield put({
                type: 'queryPageForArea',
                payload: responsedata,
                });


                if (callback) callback();
            },
            *delete_batch_for_area({ payload, callback }, { call, put }) {
                const response = yield call(deleteBatchForArea, payload);
                yield put({
                    type: 'deleteBatchForArea',
                    payload: response,
                });

                const responsedata = yield call(queryPageForArea, {});
                yield put({
                type: 'queryPageForArea',
                payload: responsedata,
                });

                if (callback) callback();
            },
            *update_batch_for_area({ payload, callback }, { call, put }) {
                const response = yield call(updateBatchForArea, payload);
                yield put({
                    type: 'updateBatchForArea',
                    payload: response,
                });

                const responsedata = yield call(queryPageForArea, {});
                yield put({
                type: 'queryPageForArea',
                payload: responsedata,
                });

                if (callback) callback();
            },
            *get_area_tree_by_parentid({ payload, callback }, { call, put }) {
                const response = yield call(getAreaTreeByParentid, payload);
                yield put({
                    type: 'getAreaTreeByParentid',
                    payload: response,
                });

                if (callback) callback();
            },
            
            *get_area_list_by_parentid({ payload, callback }, { call, put }) {
                const response = yield call(getAreaTreeByParentid, payload);
                yield put({
                    type: 'getAreaListByParentid',
                    payload: response,
                });

                if (callback) callback();
            },
            *update_change_target_node_with_source_node({ payload, callback }, { call, put }) {
                const response = yield call(updateChangeTargetNodeWithSourceNode, payload);
                yield put({
                    type: 'updateChangeTargetNodeWithSourceNode',
                    payload: response,
                });

                if (callback) callback();
            },
            },

    reducers: {
        deleteByPrimaryKeyForArea(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        selectByPrimaryKeyForArea(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        insertForArea(state, action) {
            return {
                ...state,
                recorddata: action.payload,
            };
        },
        updateForArea(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        deleteByMapForArea(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        updateByMapForArea(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        getOneForArea(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        getAllForArea(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        queryPageForArea(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        countForArea(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        insertBatchForArea(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        deleteBatchForArea(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        updateBatchForArea(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        getAreaTreeByParentid(state, action) {
            return {
                ...state,
                areaTree: action.payload,
            };
        },
        updateChangeTargetNodeWithSourceNode(state, action) {
            return {
                ...state,
                recorddata: action.payload,
            };
        },
        getAreaListByParentid(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
    },
};
